<html>
<head>
<title>快乐学围棋</title>
<meta charset="utf-8">
<link rel="stylesheet" type="text/css" href="css/wq.css" />
<link rel="stylesheet" type="text/css" href="wgo_js/wgo/wgo.player.css" />
<script type="text/javascript" src="wgo_js/wgo/wgo.min.js"></script>
<script type="text/javascript" src="wgo_js/wgo/wgo.player.min.js"></script>
<script type="text/javascript" src="wgo_js/i18n/i18n.zh.js"></script>

<?php
$Root_Path="./qipu";
function listFiles($dir="./")
{
	//遍历目录
	$dd=opendir($dir);
	while(false !== ($f=readdir($dd))){
		//过滤点
		if($f == "." ){
			continue;
		}
		if($f == ".." ){
			//拼路径
			$dir1 = rtrim($dir, "/");
			if ($dir1 != $GLOBALS['Root_Path']) 
			{
				$pos = strripos($dir1,"/");
				$dir1 = substr($dir1, 0, $pos);
				echo "<a href='main.php?a=lst&d={$dir1}'>返回上级 </a>";
				echo "<br/>";
			}
		}
		else
		{
			//拼路径
			$file=rtrim($dir,"/")."/".$f;
			//防止中文乱码
			$encode = mb_detect_encoding($f, array('ASCII','GB2312','GBK','UTF-8')); 
			if($encode =='GB2312')
				$f2=iconv("gb2312","utf-8",$f);
			if($encode =='GBK')
				$f2=iconv("GBK","utf-8",$f);
			else $f2 = $f;
			if(is_dir($file))
			{
				echo "<a href='main.php?a=lst&d={$file}'>".$f2." </a>";
				echo "<br/>";
			}
			else
			{
				echo "<a href='main.php?a=open&filename={$file}'>".$f2." </a>";
				echo "<br/>";
			}
		}
	}
}
?>
</head>
<body>
<script language="javascript">
	var tmpDate = new Date()
//	document.write(tmpDate.getYear()+1900 +"-" + (tmpDate.getMonth() + 1) + "-" + tmpDate.getDate() + "<br/>")
	//document.write(tmpDate.getDays() + "<br/>")
//	document.write(tmpDate + "<br/>")
//	document.write(tmpDate.toLocaleString() + "<br/>")
</script>
<div id=header>
<h1>快乐学围棋</h1>
</div>
<div id=nav>
<?php 
$dir = "./qipu";

if ($_GET['a']=='lst' ) 
{
	if (
		isset($_GET['d'])){
		$dir=$_GET['d'];
		listFiles("$dir");
	}
	else
		listFiles($dir);
}

if ($_GET['a']=='open' ) 
{
	$file=$_GET['filename'];
	$pos = strripos($file,"/");
	$dir = substr($file, 0, $pos);
	listFiles($dir);
}

?>

<script language="javascript">
	document.write(tmpDate.getYear()+1900 +"-" + (tmpDate.getMonth() + 1) + "-" + tmpDate.getDate() + "<br/>")
</script>
</div>
<div id=section>
<?php

	if (isset($_GET['filename'])){
		$f=$_GET['filename'];
		$myfile = fopen($f, "r") or die("Unable to open file!");
		$contents="";
		while(!feof($myfile)){
			$contents.=fread($myfile, 8192);
		}
		echo "<pre>";
		echo $contents;
		echo "</pre>";
		fclose($myfile);
	}
?>
<!-- <div data-wgo="ch1_1.sgf" style="width: 60%; margin: 0">
Your browser doesn't support WGo Player. Use some modern browser like IE9, Google Chrome or Mozilla Firefox.
</div>
-->
<div data-wgo="<?php echo $contents ?>" style = "width:100% ; margin:0"  >
你的浏览器不能很好地支持棋谱工具，建议选择使用IE9以上版本，Google Chrome 或者 Mozilla Firefox 等浏览器。
</div>
</div>
<script>
var _hmt = _hmt || [];
(function() {
   var hm = document.createElement("script");
     hm.src = "https://hm.baidu.com/hm.js?82e300c4c724dd15c0414649263730fc";
	   var s = document.getElementsByTagName("script")[0]; 
	     s.parentNode.insertBefore(hm, s);
		 })();
</script>
</body>
</html>

